package com.david.mydemo.ctl_ocr.utils;

import org.apache.commons.lang3.StringUtils;

import java.util.Base64;

/**
 * @author lyz
 * @Title: GatewayUtils
 * @Description:
 * @date 2020/9/10 9:06
 */
public class GatewayUtils {


    /**
     * 根据api网关的path映射截取capabilityName
     * @param path
     * @return
     */
    public static String getCapabilityName(String path) {
        String capabilityName = "";
        String[] pathSplit = StringUtils.split(path, "/");
        if (pathSplit[0].length() < 24) {
            capabilityName = StringUtils.rightPad(pathSplit[0], 24, '0');
        } else if (pathSplit[0].length() > 24) {
            capabilityName = pathSplit[0].substring(0, 24);
        }
        return capabilityName;
    }

    /**
     * 对字符串进行base64处理
     * @param str
     * @return
     */
    public static String getBase64(String str) {
        Base64.Encoder encoder = Base64.getEncoder();
        return encoder.encodeToString(str.getBytes());
    }
}
